package com.wxmp.market.zhuli.ctrl;

import com.wxmp.core.common.BaseCtrl;
import com.wxmp.core.util.AjaxResult;
import com.wxmp.core.util.StringUtil;
import com.wxmp.market.zhuli.domain.*;
import com.wxmp.market.zhuli.mapper.WxZhuliBaseInfoDao;
import com.wxmp.market.zhuli.mapper.WxZhuliRedeemDao;
import com.wxmp.market.zhuli.service.WxZhuliBaseInfoService;
import com.wxmp.market.zhuli.service.impl.WxZhuliBaseInfoServiceImpl;
import com.wxmp.market.zhuli.service.impl.WxZhuliJoinServiceImpl;
import com.wxmp.market.zhuli.service.impl.WxZhuliRedeemServiceImpl;
import com.wxmp.market.zhuli.service.impl.WxZhuliSendServiceImpl;
import com.wxmp.wxcms.domain.AccountFans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/zhuli")
public class ZhuliApiCtrl extends BaseCtrl {

    @Autowired
    WxZhuliBaseInfoServiceImpl baseInfoService;

    @Autowired
    WxZhuliRedeemServiceImpl redeemService;

    @Autowired
    WxZhuliSendServiceImpl sendService;

    @Autowired
    WxZhuliJoinServiceImpl joinService;

    /**
     * 活动列表
     */
    @RequestMapping(value = "/info/list")
    @ResponseBody
    public AjaxResult infoList(WxZhuliBaseInfo baseInfo) {
        List<WxZhuliBaseInfo> baseInfoList = this.baseInfoService.getActivityListByPage(baseInfo);
        return getResult(baseInfo, baseInfoList);
    }

    /**
     * 新增加一个活动
     */
    @RequestMapping(value = "/info/add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult infoAdd(WxZhuliBaseInfo baseInfo) {
        baseInfoService.add(baseInfo);
        return AjaxResult.saveSuccess();
    }

    /**
     * 获取活动详情
     */
    @RequestMapping(value = "/info/detail", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult infoDetail(@RequestParam(required = true) String baseCode) {
        WxZhuliBaseInfo baseInfo = baseInfoService.selectByBaseCode(baseCode);
        return AjaxResult.success(baseInfo);
    }

    /**
     * 修改活动
     */
    @RequestMapping(value = "/info/edit", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult infoEdit(WxZhuliBaseInfo baseInfo) {
        baseInfoService.update(baseInfo);
        return AjaxResult.updateSuccess();
    }

    /**
     * 活动数据
     * 1、关注数量
     * 2、扫码数量
     * 3、活动发起人数
     * 4、活动参与人数
     * 6、活动成功人数
     * 7、兑换码发放数
     * 8、优惠券发放数量
     */
    @RequestMapping(value = "/info/data")
    @ResponseBody
    public AjaxResult infoData(@RequestParam(required = true) String baseCode) {
        WxZhuliData zhuliData = new WxZhuliData();
        zhuliData.setJoinCount(10);
        zhuliData.setRedeemCount(1);
        zhuliData.setScanCount(100);
        zhuliData.setSendCount(200);
        zhuliData.setSubscriberCount(10);
        zhuliData.setMsgCount(300);
        zhuliData.setSuccessCount(1);
        return AjaxResult.success(zhuliData);

        //List<WxZhuliBaseInfo> baseInfos = baseInfoService.getAvailableActivityByConfig();
    }

    /**
     * 某一活动下的团发起列表
     */
    @RequestMapping(value = "/send/list", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult sendList(WxZhuliSend zhuliSend) {
        //zhuliSend.setBaseCode("1001");
        List<WxZhuliSend> sendList = sendService.list(zhuliSend);
        return getResult(zhuliSend, sendList);
    }

    /**
     * 某一活动下的团助力列表
     */
    @RequestMapping(value = "/join/list", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult joinList(WxZhuliJoin zhuliJoin) {
        HashMap<String, String> map = new HashMap<>();
        if (zhuliJoin != null) {
            if (StringUtil.isNotEmpty(zhuliJoin.getBaseCode()))
                map.put("baseCode", zhuliJoin.getBaseCode());
            if (StringUtil.isNotEmpty(zhuliJoin.getSendCode()))
                map.put("sendCode", zhuliJoin.getSendCode());
        }
        List<WxZhuliJoin> joinList = joinService.selectJoinInfoBySendCode(map);
        return getResult(zhuliJoin, joinList);
    }

    /**
     * 活动兑换码列表
     */
    @RequestMapping(value = "/redeem/list", method = RequestMethod.GET)
    @ResponseBody
    public AjaxResult redeemList(WxZhuliRedeem redeem) {
        List<WxZhuliRedeem> redeemList = redeemService.list(redeem);
        return getResult(redeem, redeemList);
    }

    @RequestMapping(value = "/redeem/edit", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult redeemEdit(WxZhuliRedeem redeem) {
        return new AjaxResult();
    }

    @RequestMapping(value = "/redeem/add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult redeemAdd(WxZhuliRedeem redeem) {
        return new AjaxResult();
    }
}
